package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IncidentDetails;
import com.ruoyi.system.service.IIncidentDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案例详情Controller
 * 
 * @author ruoyi
 * @date 2021-09-15
 */
@RestController
@RequestMapping("/system/details")
public class IncidentDetailsController extends BaseController
{
    @Autowired
    private IIncidentDetailsService incidentDetailsService;

    /**
     * 查询案例详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(IncidentDetails incidentDetails)
    {
        startPage();
        List<IncidentDetails> list = incidentDetailsService.selectIncidentDetailsList(incidentDetails);
        return getDataTable(list);
    }

    /**
     * 导出案例详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:export')")
    @Log(title = "案例详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IncidentDetails incidentDetails)
    {
        List<IncidentDetails> list = incidentDetailsService.selectIncidentDetailsList(incidentDetails);
        ExcelUtil<IncidentDetails> util = new ExcelUtil<IncidentDetails>(IncidentDetails.class);
        return util.exportExcel(list, "案例详情数据");
    }

    /**
     * 获取案例详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(incidentDetailsService.selectIncidentDetailsById(id));
    }

    /**
     * 新增案例详情
     */
    @PreAuthorize("@ss.hasPermi('system:details:add')")
    @Log(title = "案例详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IncidentDetails incidentDetails)
    {
        return toAjax(incidentDetailsService.insertIncidentDetails(incidentDetails));
    }

    /**
     * 修改案例详情
     */
    @PreAuthorize("@ss.hasPermi('system:details:edit')")
    @Log(title = "案例详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IncidentDetails incidentDetails)
    {
        return toAjax(incidentDetailsService.updateIncidentDetails(incidentDetails));
    }

    /**
     * 删除案例详情
     */
    @PreAuthorize("@ss.hasPermi('system:details:remove')")
    @Log(title = "案例详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(incidentDetailsService.deleteIncidentDetailsByIds(ids));
    }
}
